#region File Description
//-----------------------------------------------------------------------------
// OptionsMenuScreen.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using Microsoft.Xna.Framework;
#endregion

namespace TermitesMagnets
{
    /// <summary>
    /// The options screen is brought up over the top of the main menu
    /// screen, and gives the user a chance to configure the game
    /// in various hopefully useful ways.
    /// </summary>
    class OptionsMenuScreen : MenuScreen
    {
        #region Fields

        MenuEntry difficultyMenuEntry;
        MenuEntry musicMenuEntry;
        MenuEntry soundMenuEntry;

        static string[] difficulty = { "Peace of Cake", "Let's Rock", "Come Get Some", "Damn I'm Good" };
        static int currentDifficulty = GameplayScreen.Difficulty;

        static bool music = GameplayScreen.MusicEnabled;
        static bool sound = GameplayScreen.SoundsEnabled;

        static int elf = 23;

        #endregion

        #region Initialization


        /// <summary>
        /// Constructor.
        /// </summary>
        public OptionsMenuScreen()
            : base("Options")
        {
            // Create our menu entries.
            difficultyMenuEntry = new MenuEntry(string.Empty);
            musicMenuEntry = new MenuEntry(string.Empty);
            soundMenuEntry = new MenuEntry(string.Empty);


            SetMenuEntryText();

            MenuEntry back = new MenuEntry("Back");

            // Hook up menu event handlers.
            difficultyMenuEntry.Selected += DifficultyMenuEntrySelected;
            musicMenuEntry.Selected += MusicMenuEntrySelected;
            soundMenuEntry.Selected += SoundMenuEntrySelected;
            back.Selected += OnCancel;
            
            // Add entries to the menu.
            MenuEntries.Add(difficultyMenuEntry);
            MenuEntries.Add(musicMenuEntry);
            MenuEntries.Add(soundMenuEntry);
            MenuEntries.Add(back);
        }


        /// <summary>
        /// Fills in the latest values for the options screen menu text.
        /// </summary>
        void SetMenuEntryText()
        {
            difficultyMenuEntry.Text = "Difficulty: " + difficulty[currentDifficulty];
            musicMenuEntry.Text = "Music: " + (music ? "on" : "off");
            soundMenuEntry.Text = "Sound: " + (sound ? "on" : "off");
        }


        #endregion

        #region Handle Input



        /// <summary>
        /// Event handler for when the Language menu entry is selected.
        /// </summary>
        void DifficultyMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            currentDifficulty = (currentDifficulty + 1) % difficulty.Length;
            GameplayScreen.Difficulty = currentDifficulty;
            SetMenuEntryText();
        }


        /// <summary>
        /// Event handler for when the Frobnicate menu entry is selected.
        /// </summary>
        void MusicMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            music = !music;
            GameplayScreen.MusicEnabled = music;
            SetMenuEntryText();
        }


        void SoundMenuEntrySelected(object sender, PlayerIndexEventArgs e)
        {
            sound = !sound;
            GameplayScreen.SoundsEnabled = sound;
            SetMenuEntryText();
        }


        #endregion
    }
}
